import 'package:erp_widget/src/utils/screen/size_extension.dart';
import 'package:flutter/material.dart';

import 'custom.dart';
import 'model.dart';

class DxGridPopMenu extends StatelessWidget {
  final bool darkMode;
  final List<DxPopMenuModel> items;
  final DxPopMenuController controller;
  final dynamic data;

  DxGridPopMenu({
    Key? key,
    this.darkMode = true,
    required this.items,
    required this.controller,
    this.data,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 260.w,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(5.r),
        color: darkMode ? const Color(0xFF4C4C4C) : Colors.white,
      ),
      child: GridView.count(
        padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 10.h),
        crossAxisCount: 5,
        crossAxisSpacing: 0,
        mainAxisSpacing: 20.h,
        shrinkWrap: true,
        physics: const NeverScrollableScrollPhysics(),
        children: items
            .map((item) => GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: () {
                    controller.hideMenu();
                    item.callback?.call(data);
                  },
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Icon(item.icon, size: 20.w, color: darkMode ? Colors.white : Colors.black),
                      Container(
                        margin: EdgeInsets.only(top: 5.h),
                        child: Text(
                          item.title,
                          style: TextStyle(color: darkMode ? Colors.white : Colors.black, fontSize: 12.sp),
                        ),
                      ),
                    ],
                  ),
                ))
            .toList(),
      ),
    );
  }
}
